﻿using System;
using System.Collections;
using System.Globalization;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

namespace PmfWeb.Core.Utility
{
    ///<summary>
    /// 字符串操作扩展类
    ///</summary>
    public static class Utils
    {
        static Utils(){}

        #region "判断字符串是否为空 public static bool IsEmpty(string str)"
        /// <summary>
        /// 判断字符串是否为空
        /// </summary>
        /// <param name="str">要判断的字符串</param>
        /// <returns></returns>
        public static bool IsEmpty(string str)
        {
            if (String.IsNullOrEmpty(str)) return false;
            return 0 == str.Trim().Length;
        }
        #endregion

        #region "判断对象是否为null public static bool IsNull(object obj)"
        ///<summary>
        /// 判断对象是否为null
        ///</summary>
        ///<param name="obj">对象</param>
        ///<returns>是null,返回true;反之返回false</returns>
        public static bool IsNull(object obj)
        {
            return null == obj;
        }
        #endregion

        #region "判断字符串中是否包含空格字符 public static bool IsWhiteSpace(string str)"
        ///<summary>
        /// 判断字符串中是否包含空格字符
        ///</summary>
        ///<param name="str">要查找的字符串</param>
        ///<returns>包含,返回true;反之,返回false</returns>
        public static bool IsWhiteSpace(string str)
        {
            if (System.String.IsNullOrEmpty(str)) return false;
            int j = str.Length;
            for (int i = 0; i < j; i++)
            {
                if (Char.IsWhiteSpace(str, i)) return true;
                continue;
            }
            return false;
        }
        #endregion

        #region "数值类型转换实用方法"

        #region "判断多个字符串是否至少有一个为空 public static bool IsEmpty(params string[] strs)"
        /// <summary>
        /// 判断多个字符串是否至少有一个为空(过滤前后空格后)
        /// </summary>
        /// <param name="strs">字符串</param>
        /// <returns>是否至少有一个为空</returns>
        public static bool IsEmpty(params string[] strs)
        {
            foreach (string s in strs)
            {
                if (String.IsNullOrEmpty(s.Trim())) return true;
            }
            return false;
        }


        #endregion

        #region "判断已指定字符分隔的字符串里,每个分割区里是否有一个为空的字符串 public static bool IsEmpty(string strs, char c)"
        /// <summary>
        /// 判断已指定字符分隔的字符串里,每个分割区里是否有一个为空的字符串
        /// </summary>
        /// <param name="strs">要判断的字符串</param>
        /// <param name="c">分隔符</param>
        /// <returns>是否至少有一个为空</returns>
        public static bool IsEmpty(string strs, char c)
        {
            return IsEmpty(strs.Split(c));
        }
        #endregion

        #region "转换字符串类型变量为Int类型 public static int ToInt(string str, int iMin, int iMax, int iDefault)"
        ///<summary>
        /// 转换字符串类型变量为Int类型
        ///</summary>
        ///<param name="str">要转换的字符串类型值</param>
        ///<param name="iMin">最小值</param>
        ///<param name="iMax">最大值</param>
        ///<param name="iDefault">默认值</param>
        ///<returns>转换后的整形值</returns>
        ///<exception cref="ArgumentNullException">要转换的字符串未输入或为null,引发参数异常</exception>
        //[Obsolete("要转换的字符串不能为空!")]
        public static int ToInt(string str, int iMin, int iMax, int iDefault)
        {
            if (String.IsNullOrEmpty(str)) return iDefault;
            int result = 0;
            if (Int32.TryParse(str.Trim(), out result))
            {
                if (iMin > result || iMax < result) return iDefault;
                return result;
            }
            return iDefault;
        }
        #endregion

        #region "转换字符串类型变量为Int类型,默认值可指定. public static int ToInt(string str, int iDefault, bool isSign)"
        /// <summary>
        /// 转换字符串类型变量为Int类型,默认值可指定.
        /// </summary>
        /// <param name="str">要转换的字符串类型值</param>
        /// <param name="iDefault">默认值</param>
        /// <param name="isSign">为True包含负值,反之不包含</param>
        /// <returns>转换后的整形值</returns>
        public static int ToInt(string str, int iDefault, bool isSign)
        {
            int iMin = 0;
            if (isSign) iMin = Int32.MinValue;
            return ToInt(str, iMin, Int32.MaxValue, iDefault);
        }
        #endregion

        #region "转换字符串类型变量为Int类型,默认值为0(不包含负值). public static int ToInt(string str)"
        /// <summary>
        /// 转换字符串类型变量为Int类型,默认值为0(不包含负值).
        /// </summary>
        /// <param name="str">要转换的字符串类型值</param>
        /// <returns>转换后的整形值</returns>
        public static int ToInt(string str)
        {
            return ToInt(str, 0, true);
        }

        /// <summary>
        /// 转换字符串类型变量为Int类型,默认值为0(不包含负值).
        /// </summary>
        /// <param name="str">要转换的字符串类型值</param>
        /// <param name="isSign">true,包含负数,false只为正数和零</param>
        /// <returns>转换后的整形值</returns>
        public static int ToInt(string str, bool isSign)
        {
            return ToInt(str, 0, isSign);
        }
        #endregion

        /// <summary>
        /// 转换对象类型到双精度数值类型
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <param name="dDefault">转换失败返回的值</param>
        /// <returns>转换后的双精度类型</returns>
        public static double ToDouble(object obj, double dDefault)
        {
            if (null == obj) return dDefault;
            return ToDouble(obj.ToString(), dDefault);
        }
        /// <summary>
        /// 转换字符串类型到双精度数值类型
        /// </summary>
        /// <param name="str">要转换的字符串</param>
        /// <param name="dDefault">转换失败返回的值</param>
        /// <returns>转换后的双精度类型</returns>
        public static double ToDouble(string str, double dDefault)
        {
            if (String.IsNullOrEmpty(str)) return dDefault;
            double result = 0.0d;
            return double.TryParse(str, out result) ? result : dDefault;
        }
        /// <summary>
        /// 转换字符串类型到双精度数值类型,转换失败后返回0.0
        /// </summary>
        /// <param name="str">要转换的字符串</param>
        /// <returns>转换后的双精度类型</returns>
        public static double ToDouble(string str)
        {
            return ToDouble(str, 0.0d);
        }

        /// <summary>
        /// 转换对象类型到小数类型
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <param name="dDefault">转换失败返回的值</param>
        /// <returns>转换成功,返回的小数类型值,失败返回默认值</returns>
        public static decimal ToDecimal(object obj, decimal dDefault)
        {
            if (null == obj) return dDefault;
            return ToDecimal(obj.ToString(), dDefault);
        }
        /// <summary>
        /// 转换字符串类型到小数类型
        /// </summary>
        /// <param name="str">要转换的字符串</param>
        /// <param name="dDefault">转换失败返回的值</param>
        /// <returns>转换成功返回的小数类型值,失败返回默认值</returns>
        public static decimal ToDecimal(string str, decimal dDefault)
        {
            if (String.IsNullOrEmpty(str)) return dDefault;
            decimal d = 0.0m;
            return decimal.TryParse(str.Trim(), out d) ? d : dDefault;
        }

        ///<summary>
        /// 小数类型字符串转换为整形
        ///</summary>
        ///<param name="strDecimal">小数字符串</param>
        ///<returns>整型值</returns>
        public static int DecimalToInt(string strDecimal)
        {
            decimal idefault = ToDecimal(strDecimal);
            return (int) idefault;
        }


        /// <summary>
        /// 转换对象类型到小数类型
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <returns>转换成功,返回的小数类型值,失败返回0.0m</returns>
        public static decimal ToDecimal(object obj)
        {
            return ToDecimal(obj, 0.0m);
        }

        /// <summary>
        /// 转换object对象为Int类型,转换失败返回0
        /// </summary>
        /// <param name="obj">要转换得对象</param>
        /// <returns>转换后的字符串</returns>
        public static int ToInt(object obj)
        {
            return ToInt(obj, 0);
        }




        #region "转换字符串值为小数类型 public static decimal ToDecimal(string str)"
        /// <summary>
        /// 转换字符串值为小数类型,失败返回0.0
        /// </summary>
        /// <param name="str">要转换的字符串</param>
        /// <returns>转换成功返回的小数类型值,失败返回0.0</returns>
        public static decimal ToDecimal(string str)
        {
            return ToDecimal(str, 0.0m);
        }
        #endregion

        #region "转换字符串类型变量为Int类型,默认值为0(不包含负值). public static int ToInt(string str)"
        /// <summary>
        /// 转换字符串类型变量为Int类型,默认值为0(不包含负值).
        /// </summary>
        /// <param name="str">要转换的字符串类型值</param>
        /// <param name="iDefault">默认值</param>
        /// <returns>转换后的整形值</returns>
        public static int ToInt(string str, int iDefault)
        {
            return ToInt(str, iDefault, false);
        }
        #endregion

        #region "转换字符串类型为单精度类型 public static float ToFloat(string str)"
        ///<summary>
        /// 转换字符串类型为单精度类型
        ///</summary>
        ///<param name="str">要转换的字符串</param>
        ///<returns>转换后的单精度变量</returns>
        public static float ToFloat(string str)
        {
            return ToFloat(str, 0f);
        }
        #endregion

        #region "转换字符串到日期类型 public static DateTime ToDateTime(string str,DateTime dDefault)"
        ///<summary>
        /// 转换字符串到日期类型
        ///</summary>
        ///<param name="str">要转换的字符串</param>
        ///<param name="dDefault">转换失败后返回的默认值</param>
        ///<returns>转换后的日期类型对象</returns>
        public static DateTime ToDateTime(string str, DateTime dDefault)
        {
            if (String.IsNullOrEmpty(str)) return dDefault;
            DateTime result;
            DateTime.TryParse(str, out result);
            return result;
        }
        /// <summary>
        /// 转换字符串到日期类型,转换失败返回日期的最小值
        /// </summary>
        /// <param name="str">要转换的字符串</param>
        /// <returns>转换后的日期类型对象</returns>
        public static DateTime ToDateTime(string str)
        {
            return ToDateTime(str, DateTime.MinValue);
        }

        /// <summary>
        ///  转换object到日期类型,转换失败返回日期的最小值
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(object obj)
        {
            if (null == obj) return DateTime.Now;
            return ToDateTime(obj.ToString(), DateTime.MinValue);
        }

        /// <summary>
        /// 转换object对象到字符串,无法转换的话,返回DateTime.MinValue值
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <param name="sFormat">时间的格式</param>
        /// <returns>转换成功,返回指定时间格式字符串,反之返回DateTime.MinValue值</returns>
        public static string ToDateTime(object obj, string sFormat)
        {
            if (null == obj) return DateTime.MinValue.ToString(sFormat);
            return ToDateTime(obj.ToString()).ToString(sFormat);
        }
        #endregion

        #region "转换字符串类型为单精度类型,并指定转换失败后返回值 public static float ToFloat(string str, float fDefault)"
        /// <summary>
        /// 转换字符串类型为单精度类型,并指定转换失败后返回值
        /// </summary>
        /// <param name="str">要转换的字符串</param>
        /// <param name="fDefault">失败后返回的值</param>
        /// <returns>转换成功返回实践值,失败返回默认值</returns>
        public static float ToFloat(string str, float fDefault)
        {
            if (System.String.IsNullOrEmpty(str)) return fDefault;
            float result;
            return float.TryParse(str, out result) ? result : fDefault;
        }
        #endregion

        #region "转换对象类型为单精度类型,并指定转换失败后返回值 public static float ToFloat(object obj, float fDefault)"
        /// <summary>
        /// 转换对象类型为单精度类型,并指定转换失败后返回值
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <param name="fDefault">失败后返回的默认值</param>
        /// <returns>转换成功返回实践值,失败返回默认值</returns>
        public static float ToFloat(object obj, float fDefault)
        {
            if (null == obj) return fDefault;
            return ToFloat(obj.ToString(), fDefault);
        }

        #endregion

        #region "转换字符成bool类型 public static bool ToBool(string str)"
        /// <summary>
        /// 转换字符成bool类型
        /// </summary>
        /// <param name="str">要转换的字符串</param>
        /// <returns>默认返回false</returns>
        public static bool ToBool(string str)
        {
            return ToBool(str, false);
        }
        #endregion

        #region "转换object类型成bool类型 public static bool ToBool(object obj, bool bDefault)"
        /// <summary>
        /// 转换object类型成bool类型
        /// </summary>
        /// <param name="obj">要转换的object类型对象</param>
        /// <param name="bDefault">转换失败时的默认值</param>
        /// <returns>转换成功返回true,失败返回默认值</returns>
        public static bool ToBool(object obj, bool bDefault)
        {
            bool result = false;
            Boolean.TryParse(obj.ToString(), out result);
            return result ? true : bDefault;
        }
        #endregion

        #region "转换object类型成bool类型 public static bool ToBool(object obj)"
        /// <summary>
        /// 转换object类型成bool类型
        /// </summary>
        /// <param name="obj">要转换的object类型对象</param>
        /// <returns>转换成功返回true,失败返回false</returns>
        public static bool ToBool(object obj)
        {
            return ToBool(obj, false);
        }
        #endregion

        #region "转换字符成bool类型,指定默认值,转换失败时返回默认值. public static bool ToBool(string str, bool bDefault)"
        ///<summary>
        /// 转换字符成bool类型,指定默认值,转换失败时返回默认值.
        ///</summary>
        ///<param name="str">字符串</param>
        ///<param name="bDefault">默认值</param>
        ///<returns>成功返回true, 失败返回默认值</returns>
        public static bool ToBool(string str, bool bDefault)
        {
            bool reuslt = false;
            Boolean.TryParse(str, out reuslt);
            return reuslt ? true : bDefault;
        }
        #endregion

        #region "转换字符串为long类型 public static long ToLong(string str)"
        /// <summary>
        /// 转换字符串为long类型
        /// </summary>
        /// <param name="str">字符串类型</param>
        /// <returns>long类型或0</returns>
        public static long ToLong(string str)
        {
            long result = 0;
            if (IsEmpty(str)) return 0;
            return Int64.TryParse(str, out result) ? result : 0;
        }
        #endregion

        #region "转换对象类型为长整型 public static long ToLong(object str)"
        ///<summary>
        /// 转换对象类型为长整型
        ///</summary>
        ///<param name="obj">对象类型</param>
        ///<returns>长整型结果</returns>
        public static long ToLong(object obj)
        {
            return ToLong(obj.ToString());
        }
        #endregion

        #region "转换object类型为int类型,转换失败则返回iDefault值 public static int ToInt(object obj, int iDefault)"
        /// <summary>
        /// 转换object类型为int类型,转换失败则返回iDefault值
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <param name="iDefault">默认值</param>
        /// <returns>转换后的值</returns>
        public static int ToInt(object obj, int iDefault)
        {
            if (null == obj) return iDefault;
            int result = 0;
            return Int32.TryParse(obj.ToString(), out result) ? result : iDefault;
        }
        #endregion

        #region 判断判断对象是否DateTime类型 public static bool IsDateTime(object obj)
        /// <summary>
        /// 判断判断对象是否DateTime类型
        /// </summary>
        /// <param name="obj">要判断的对象</param>
        /// <returns>是,返回true;反之,返回false</returns>
        public static bool IsDateTime(object obj)
        {
            if (null == obj) return false;
            if (obj.GetType() == typeof(DateTime)) return true;
            DateTime result;
            return DateTime.TryParse(obj.ToString(), DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out result);
        }
        #endregion

        #region 数值类型相互转换(泛型方式) public static T ConvertTo<U,T>(U obj, T tDefault)
        ///<summary>
        /// 数值类型类型转换 public static T ConvertTo<U,T>(U obj, T tDefault) where T : struct, IComparable where U : struct ,IComparable
        ///</summary>
        ///<param name="obj">要转换的数值</param>
        ///<param name="tDefault">转换失败后的默认返回值</param>
        ///<returns>成功,返回转换后的值;失败返回tDefault值</returns>
        public static T ConvertTo<U, T>(U obj, T tDefault)
            where T : struct, IComparable
            where U : IComparable
        {
            T result;
            try
            {
                result = Convert.ChangeType(obj, typeof(T)) is T ? (T)Convert.ChangeType(obj, typeof(T)) : default(T);
            }
            catch (FormatException fx)
            {
                result = tDefault;
            }
            catch (ArgumentException ax)
            {
                result = tDefault;
            }
            catch (InvalidCastException ix)
            {
                result = tDefault;
            }
            return result;
        }
        #endregion 数值类型转换方法结束

        #region 判断数组是否全为数字 public static bool IsNumberArray(string[] str)
        ///<summary>
        /// 判断数组是否全为数字
        ///</summary>
        ///<param name="str">要判断字符串数组</param>
        ///<returns>是返回true,反之,返回false</returns>
        public static bool IsNumberArray(string[] str)
        {
            if (null == str || str.Length < 1) return false;
            foreach (string s in str)
            {
                if (Regex.IsMatch(s, @"[^0-9\-]")) return false;
            }
            return true;
        }
        #endregion
        #endregion

        #region "字符串操作增强方法"

        #region 去除字符串前缀(前缀字符串)  public static string RemoveStart(string str, string remove)
        /// <summary>
        /// 去除字符串前缀(前缀字符串)
        /// </summary>
        /// <param name="str">要清理的字符串</param>
        /// <param name="remove">前缀字符串</param>
        /// <returns>如果remove是str的前缀,则返回去除后的字符串;反之返回原str字符串</returns>
        public static string RemoveStart(string str, string remove)
        {
            if(String.IsNullOrEmpty(str) || String.IsNullOrEmpty(remove)) return str;
            if (str.StartsWith(remove))
            {
                return str.Substring(remove.Length - 1, str.Length - remove.Length);
            }
            return str;
        }
        #endregion

        #region 去除字符串后缀(后缀字符串) public static string RemoveEnd(string str, string remove)
        /// <summary>
        /// 去除字符串后缀(后缀字符串)
        /// </summary>
        /// <param name="str">要清理的字符串</param>
        /// <param name="remove">后缀字符串</param>
        /// <returns>如果remove是str的后缀,则返回去除后的字符串;反之返回原str字符串</returns>
        public static string RemoveEnd(string str, string remove)
        {
            if (str.EndsWith(remove))
            {
                return str.Substring(0, str.Length - remove.Length);
            }
            return str;
        }
        #endregion

        #region 获取字符串在数组中的位置 public static int IndexOfArray(string str, string[] stringArray, bool isCase)
        /// <summary>
        /// 获取字符串在数组中的位置
        /// </summary>
        /// <param name="str">要搜索的字符串</param>
        /// <param name="stringArray">搜索的字符串数组</param>
        /// <param name="isCase">是否区分大小写</param>
        /// <returns>字符串在数组中的位置</returns>
        public static int IndexOfArray(string str, string[] stringArray, bool isCase)
        {
            for (int i = 0; i < stringArray.Length; i++)
            {
                if (isCase)
                {
                    if (str.ToLower() == stringArray[i].ToLower())
                    {
                        return i;
                    }
                }
                else
                {
                    if (str == stringArray[i])
                    {
                        return i;
                    }
                }
            }
            return -1;
        }
        #endregion

        #region 获取字符串在数组中的位置 public static int IndexOfArray(string str, string source, bool isCase)
        /// <summary>
        /// 获取字符串在数组中的位置
        /// </summary>
        /// <param name="str">要查找的字符串</param>
        /// <param name="source">目标字符串</param>
        /// <param name="isCase">是否区分大小写</param>
        /// <returns>返回字符串的位置</returns>
        public static int IndexOfArray(string str, string source, bool isCase)
        {
            CompareInfo info = CultureInfo.InvariantCulture.CompareInfo;
            return !isCase ? info.IndexOf(str, source, CompareOptions.IgnoreCase) : info.IndexOf(str, source);
        }
        #endregion

        #region 判断字符串是否包含在字符串数组中 public static bool IsInArray(string str, string[] targets)
        /// <summary>
        /// 判断字符串是否包含在字符串数组中
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="targets">字符串数组</param>
        /// <returns>包含返回true,反之返回false</returns>
        public static bool IsInArray(string str, string[] targets)
        {
            return IndexOfArray(str, targets, false) > 0;
        }
        #endregion

        #region 判断一个值是否在指定的数组内 public static bool IsInArray(int i, int[] source)
        /// <summary>
        /// 判断一个值是否在指定的数组内
        /// </summary>
        /// <param name="i">要判断的值</param>
        /// <param name="source">整数数组</param>
        /// <returns>在,返回true,反之,返回false</returns>
        public static bool IsInArray(int i, int[] source)
        {
            int iLenght = source.Length;
            if (0 == iLenght) return false;
            for (int j = 0; j < iLenght; j++)
            {
                if (i == source[j]) return true;
            }
            return false;
        }
        #endregion

        #region 判断一个值是否在指定的数组内 public static bool IsInArray(int i, int iMin, int iMax)
        /// <summary>
        /// 判断一个值是否在指定的值范围内
        /// </summary>
        /// <param name="i">要判断的值</param>
        /// <param name="iMin">最小值</param>
        /// <param name="iMax">最大值</param>
        /// <returns>在,返回true,反之,返回false</returns>
        public static bool IsInArray(int i, int iMin, int iMax)
        {
            return (i >= iMin && i <= iMax);
        }
        #endregion

        #region 截取字符串(字符串长度小于iMax时不添加) public static string Left(string str, int length, bool flg)
        /// <SUMMARY>   
        /// 截取字符串长度,双字节字符按长度为2计算  
        /// </SUMMARY>   
        /// <param name="str">要截取的字符串</param>   
        /// <param name="rStr">要补充的字符串(如"...")</param>
        /// <param name="flg">true:加,flase:不加</param>   
        /// <param name="ilenght">需要的长度(双字节字符算2个长度)</param>
        /// <returns></returns>   
        public static string Left(string str, int ilenght, string rStr, bool flg)
        {
            int i = 0, j = 0;
            foreach (char chr in str)
            {
                if ((int)chr > 127)
                {
                    i += 2;
                }
                else
                {
                    i++;
                }
                if (i > ilenght)
                {
                    str = str.Substring(0, j);
                    if (flg)
                        str += rStr;
                    break;
                }
                j++;
            }
            return str;
        }
        #endregion

        #region 截断字符串的指定前iMax个字符,并添加"..."号 public static string Left(string str,int iLenght)
        /// <summary>
        /// 截断字符串的指定前iMax个字符,并添加"..."号(字符串长度小于iMax时不添加)
        /// </summary>
        /// <param name="str">要截断的字符串</param>
        /// <param name="iMax">需要的长度</param>
        /// <returns>截断后的字符串</returns>
        public static string Left(string str, int iMax)
        {
            return Left(str, iMax, "...", true);
        }
        #endregion

        #region 截取字符串的前iMax个字符(字符串长度小于iMax时不添加). public static string Left(string str, int iMax,bool flag)
        ///<summary>
        /// 截取字符串的前iMax个字符
        ///</summary>
        ///<param name="str">要截取的字符串</param>
        ///<param name="iMax">最大长度</param>
        ///<param name="flag">是否要添加"..."</param>
        ///<returns>截取后的字符串</returns>
        public static string Left(string str, int iMax, bool flag)
        {
            return Left(str, iMax, "...", flag);
        }
        #endregion

        #region 截取字符串+… public static string CutString(string strInput, int intlen)
        /// <SUMMARY>   
        ///  截取字符串,超过部分添加"… "   
        /// </SUMMARY>   
        /// <PARAM name="strInput">要截取的字符串</PARAM>   
        /// <PARAM name="intlen">需要的长度</PARAM>   
        /// <returns>截取后的字符串</returns>   
        public static string CutString(string strInput, int intlen)
        {
            ASCIIEncoding ascii = new ASCIIEncoding();
            int intLength = 0;
            string strString = "";
            byte[] s = ascii.GetBytes(strInput);
            for (int i = 0; i < s.Length; i++)
            {
                if ((int)s[i] == 63)
                {
                    intLength += 2;
                }
                else
                {
                    intLength += 1;
                }

                try
                {
                    strString += strInput.Substring(i, 1);
                }
                catch
                {
                    break;
                }

                if (intLength > intlen)
                {
                    break;
                }
            }
            //如果截过则加上半个省略号   
            byte[] mybyte = System.Text.Encoding.Default.GetBytes(strInput);
            if (mybyte.Length > intlen)
            {
                strString += "…";
            }
            return strString;
        }

        /// <summary>
        /// 截取字符串,超过部分添加"… "
        /// </summary>
        /// <param name="obj">要截取的字符串对象</param>
        /// <param name="len">需要的长度</param>
        /// <returns>截取后的字符串</returns>
        public static string CutString(object obj, int len)
        {
            if (null == obj) return "";
            return CutString(obj.ToString(), len);
        }
        #endregion

        #region 获取Web.config中的配置字节值 public static string GetConfig(string key)
        /// <SUMMARY>   
        /// 获取全局配置参数   
        /// </SUMMARY>   
        /// <param name="key">键名</param>   
        /// <returns>参数</returns>   
        public static string GetConfig(string key)
        {
            #region 放弃的方式
            //System.Configuration.AppSettingsReader app = new System.Configuration.AppSettingsReader();

            //string str = (string)app.GetValue(key, typeof(string));
            //if (string.IsNullOrEmpty(str)) return null;
            //return str;
            #endregion

            return ConfigHelper.GetString(key);
        }
        #endregion

        #region "比较字符串(忽略大小写,不区分语言) public static bool ToEquals(string str1, string str2)"
        /// <summary>
        /// 忽略大小写的字符串比较,不分语言
        /// </summary>
        /// <param name="str1">字符串1</param>
        /// <param name="str2">字符串2</param>
        /// <returns>相同返回true,不同返回false</returns>
        public static bool ToEquals(string str1, string str2)
        {
            return str1.Equals(str2, StringComparison.OrdinalIgnoreCase);
        }

        ///<summary>
        ///比较多个变量与字符串是否相等,适合多条件相等判断,即逻辑与和逻辑或判断(忽略大小写,不区分语言)
        ///</summary>
        ///<param name="isAll">true表示全部相等,false表示至少一个相等</param>
        ///<param name="keys">要比较的变量和字符串值</param>
        ///<returns>结果值</returns>
        public static bool ToEquals(bool isAll, params string[] keys)
        {
            int ilen = keys.Length;
            int m = 0;
            if (0 != (ilen % 2)) throw new Exception("keys参数个数必须成对出现,即必须是2的整数倍。");
            m = ilen / 2;
            int t = m;
            for (int j = 0; j < t; j++)
            {
                if (isAll)
                {
                    if (keys[j].Equals(keys[m++], StringComparison.OrdinalIgnoreCase)) continue;
                    return false;
                }
                if (!keys[j].Equals(keys[m++], StringComparison.OrdinalIgnoreCase)) continue;
                return true;
            }
            return isAll;
        }

        ///<summary>
        ///比较多个变量与字符串是否不相等,适合多条件相等判断,即逻辑与和逻辑或判断(忽略大小写,不区分语言)
        ///</summary>
        ///<param name="isAll">true表示全部不相等,false为至少一个不相等</param>
        ///<param name="keys">要比较的变量和字符串值</param>
        ///<returns>结果值</returns>
        public static bool ToNotEquals(bool isAll, params string[] keys)
        {
            int ilen = keys.Length;
            int m = 0;
            if (0 != (ilen % 2)) throw new Exception("keys参数个数必须成对出现,即必须是2的整数倍。");
            m = ilen / 2;
            int t = m;

            for (int j = 0; j < t; j++)
            {
                if (isAll)
                {
                    if (!keys[j].Equals(keys[m++], StringComparison.OrdinalIgnoreCase)) continue;
                    return false;
                }
                if (keys[j].Equals(keys[m++], StringComparison.OrdinalIgnoreCase)) continue;
                return true;
            }
            return isAll;
        }

        #endregion

        #region "获取中文星期日期 public static string GetWeek(DateTime sDate)"
        /// <summary>
        /// 获取中文星期日期
        /// </summary>
        /// <param name="sDate">日期对象</param>
        /// <returns>返回如:星期一,星期二等字符串</returns>
        public static string GetWeek(DateTime sDate)
        {
            Calendar myCal = CultureInfo.InvariantCulture.Calendar;
            string result = "";
            switch (myCal.GetDayOfWeek(sDate).ToString())
            {
                case "Sunday":
                    result = "星期日";
                    break;
                case "Monday":
                    result = "星期一";
                    break;
                case "Tuesday":
                    result = "星期二";
                    break;
                case "Wednesday":
                    result = "星期三";
                    break;
                case "Thursday":
                    result = "星期四";
                    break;
                case "Friday":
                    result = "星期五";
                    break;
                case "Saturday":
                    result = "星期六";
                    break;
            }
            return result;
        }
        #endregion

        #region "隐藏IP地址最后一位用*号代替 public static string HidenLastIp(string Ipaddress)"
        /// <summary>
        /// 隐藏IP地址最后一位用*号代替
        /// </summary>
        /// <param name="ip">IP地址:192.168.34.23</param>
        /// <returns></returns>
        public static string HidenLastIp(string ip)
        {
            return ip.Substring(0, ip.LastIndexOf(".")) + ".*";
        }
        #endregion

        #region "Html字符串加解码处理方法 public static string Decode(string str)"
        /// <summary>
        /// 解码Html字符串
        /// </summary>
        /// <param name="str">目标字符串</param>
        /// <returns>解码后的字符串</returns>
        public static string Decode(string str)
        {
            str = str.Replace("<br>", "\n");
            str = str.Replace("&gt;", ">");
            str = str.Replace("&lt;", "<");
            str = str.Replace("&nbsp;", " ");
            str = str.Replace("&quot;", "\"");
            return str;
        }

        /// <summary>
        /// 编码(过滤)Html字符串
        /// </summary>
        /// <param name="str">目标字符串</param>
        /// <returns>编码后的字符串</returns>
        public static string Encode(string str)
        {
            str = str.Replace("&", "&amp;");
            str = str.Replace("'", "''");
            str = str.Replace("\"", "&quot;");
            str = str.Replace(" ", "&nbsp;");
            str = str.Replace("<", "&lt;");
            str = str.Replace(">", "&gt;");
            str = str.Replace("\n", "<br>");
            return str;
        }

        /// <summary>
        /// 过滤Html字符串
        /// </summary>
        /// <param name="inputData">待过滤字符串</param>
        /// <returns>过滤后的字符串</returns>
        public static string HtmlEncode(string inputData)
        {
            return System.Web.HttpUtility.HtmlEncode(inputData);
        }
        #endregion

        #region "去除字符串里的单引号(替换为"") public static string RemoveSql(string str)"
        /// <summary>
        /// 去除字符串里的单引号(替换为"")
        /// </summary>
        /// <param name="str">要处理的字符串</param>
        /// <returns>去掉单引号后的字符串</returns>
        public static string RemoveSql(string str)
        {
            if (System.String.IsNullOrEmpty(str)) return "";
            return str.Replace("'", "");
        }
        #endregion

        #region "数字添加前导字符"0"字符 public static string AddZero(int i)"
        /// <summary>
        /// 数字前导加0
        /// </summary>
        /// <param name="Int">要操作的 int  数据</param>
        /// <param name="iMax">最大长度</param>
        /// <returns>string</returns>
        public static string AddZero(int Int, int iMax)
        {
            return AddZero(Int.ToString(), iMax);
        }

        /// <summary>
        /// 数字前导加0
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <param name="iMax">默认长度不加0</param>
        /// <returns>字符</returns>
        public static string AddZero(string obj, int iMax)
        {
            int iLength = obj.Length;
            if (iLength < iMax)
            {
                for (int i = 1; i <= (iMax - iLength); i++) obj = "0" + obj;
            }
            return obj;
        }
        #endregion

        #region "获取指定范围内的随机数 public static int GetRandom(int iMin,int iMax)"
        /// <summary>
        /// 获取指定范围内的随机数
        /// </summary>
        /// <param name="iMin">最小值</param>
        /// <param name="iMax">最大值</param>
        /// <returns>产生的随机数值</returns>
        public static int GetRandom(int iMin, int iMax)
        {
            Random random = new System.Random(GetNewSeed());
            return random.Next(iMin, iMax);
        }

        /// <summary>
        /// 随机获取指定字符串数组中的任意一个项.
        /// </summary>
        /// <param name="iIndex">输出取的元素的索引值</param>
        /// <param name="strs">字符串数组</param>
        /// <returns>随机的字符串</returns>
        public static string GetRandom(out int iIndex, params string[] strs)
        {
            int i = strs.Length;
            iIndex = -1;
            if (1 >= i) return strs[0];
            Random rand = null;
            for (int j = 0; j < strs.Length; j++)
            {
                rand = new Random(Guid.NewGuid().GetHashCode());
                iIndex = rand.Next(0, i - 1);
                if (strs[iIndex] == "") continue;
                break;
            }
            return strs[iIndex];
        }
        #endregion

        #region "产生随机种子,短时大量随机数的生成,不宜采用 public static int GetNewSeed()"
        /// <summary>
        /// 获取随机种子,RNGCryptoServiceProvider 做种，可以在一秒内产生的随机数重复率非常低.缺点,比较耗时.短时大量随机数的生成,不宜采用
        /// </summary>
        /// <returns>种子值</returns>
        public static int GetNewSeed()
        {
            byte[] bits = new byte[4];
            RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
            provider.GetBytes(bits);
            return BitConverter.ToInt32(bits, 0);
        }
        #endregion

        #region "返回标准时间 public static string GetStandardDate(string str)"
        /// <summary>
        /// 返回标准时间 yyyy-MM-dd
        /// </sumary>
        public static string GetStandardDate(string str)
        {
            DateTime result;
            DateTime.TryParse(str, out result);
            return result.ToString("yyyy-MM-dd");
        }
        #endregion

        #region "拆分字符串数组,并返回指定字符分隔的字符串 public static string ArrayToString(string[] strs, string splitString)"
        ///<summary>
        /// 拆分字符串数组,并返回指定字符(非空)分隔的字符串
        ///</summary>
        ///<param name="strs">要拆分的字符串数组</param>
        ///<param name="splitString">分隔字符串</param>
        ///<returns>拆分后的字符串</returns>
        public static string ArrayToString(string[] strs, string splitString)
        {
            if (null == strs || 0 == strs.Length) return "";
            return String.Join(splitString, strs);
        }

        #endregion

        #region "拆分字符串数组,并返回逗号分隔的字符串 public static string ArrayToString(string[] strs)"
        /// <summary>
        /// 拆分字符串数组,并返回逗号分隔的字符串
        /// </summary>
        /// <param name="strs">要拆分的字符串数组</param>
        /// <returns>逗号分隔的字符串</returns>
        public static string ArrayToString(string[] strs)
        {
            return ArrayToString(strs, "");
        }
        #endregion

        #region "转换字符为字符串数组 public static string[] ToArray(string strs, string c, bool isKeepEmpty)"
        /// <summary>
        /// 转换字符为字符串数组
        /// </summary>
        /// <param name="strs">要转换的字符串</param>
        /// <param name="c">分隔字符串</param>
        /// <param name="isKeepEmpty">是否保留值为空项</param>
        /// <returns>拆分后的字符串数组</returns>
        public static string[] ToArray(string strs, string c, bool isKeepEmpty)
        {
            return strs.Split(new string[] { c }, isKeepEmpty ? StringSplitOptions.None : StringSplitOptions.RemoveEmptyEntries);
        }
        #endregion

        #region "删除数组指定位置的元素,并返回删除后的数组"
        /// <summary>
        ///  删除数组指定位置的元素,并返回删除后的数组
        /// </summary>
        /// <param name="strs">要操作的数组</param>
        /// <param name="i">位置</param>
        /// <returns>删除指定位置上的元素后的数组</returns>
        public static string[] RemoveIndexOfArray(string[] strs, int i)
        {
            int sLen = strs.Length;
            if (0 == sLen || 0 >= i || sLen < i) return strs;
            int m = 0;
            string[] result = new string[sLen - 1];
            for (int j = 0; j < sLen; j++)
            {
                if (i != j) result[m++] = strs[j];
                continue;
            }
            return result;
        }
        #endregion


        #endregion 字符串操作结束

        #region IP地址屏蔽方法 public static long IpToLong(IPAddress ipAddress)

        #region 把IP地址转化为长整数 public static long IpToLong(IPAddress ipAddress)
        /// <summary>
        /// 把IP地址转化为长整数
        /// </summary>
        /// <param name="ipAddress">IPAddress对象</param>
        /// <returns>长整型结果</returns>
        public static long IpToLong(IPAddress ipAddress)
        {
            int iBit = 3;
            long lResult = 0;
            foreach (byte iByte in ipAddress.GetAddressBytes())
            {
                lResult += (long)iByte << 8 * iBit--;
            }
            return lResult;
        }
        #endregion

        #region 长整数转化成IP地址 public static IPAddress LongToIp(long l)
        /// <summary>
        /// 长整数转化成IP地址
        /// </summary>
        /// <param name="l">要转化的长整数</param>
        /// <returns>IPAddress对象</returns>
        public static IPAddress LongToIp(long l)
        {
            byte[] temps = new byte[4];
            for (int i = 0; i < temps.Length; i++)
            {
                temps[3 - i] = (byte)(l >> 8 * i & 255);
            }
            return new IPAddress(temps);
        }
        #endregion

        #endregion

        #region 删除字符串中的HMTL标记和Script代码,用于长文章分页 public static string RemoveHtml(string source)
        /// <summary>
        /// 删除字符串中的HMTL标记和Script代码,用于长文章分页
        /// </summary>
        /// <param name="source">要过滤的字符串</param>
        /// <returns>删除HMTL标记和Script代码后的字符串</returns>
        public static string RemoveHtml(string source)
        {
            //删除脚本 
            source = Regex.Replace(source, @" <script[^>]*?>.*? </script>", "", RegexOptions.IgnoreCase);
            //删除HTML 
            source = Regex.Replace(source, @" <(.[^>]*)>", "", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"-->", "", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @" <!--.*", "", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(lt|#60);", " <", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
            source = Regex.Replace(source, @"&#(\d+);", "", RegexOptions.IgnoreCase);

            source.Replace(" <", "");
            source.Replace(">", "");
            source.Replace("\r\n", "");
            //source = HttpContext.Current.Server.HtmlEncode(source).Trim();
            return source;
        }
        #endregion

        #region 加密字符串,使它能保存到web.config文件中
        /// <summary>
        /// 加密字符串,使它能保存到web.config文件中
        /// </summary>
        /// <param name="str">要加密的字符串</param>
        /// <param name="isMD5">是否是MD5加密算法(反之SHA1加密算法)</param>
        /// <returns>返回加密后的字符串</returns>
        public static string EncryptXML(string str, bool isMD5)
        {
            string temp = "MD5";
            if (!isMD5) temp = "SHA1";
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, temp);
        }
        #endregion

        #region 判断字符串是否包含sql危险字符
        /// <summary>
        /// 用户输入的字符串检查
        /// </summary>
        /// <param name="str">输入字符串</param>
        /// <returns>通过返回1,不通过返回小于0</returns>
        public static bool CheckStr(string str)
        {
            string reg =
                @"insert |delete |count\(|asc\(|mid\(|char\(|exec master|net user|net localgroup administrators|or |and |update|drop table|truncate|xp_cmdshell|create |alert |'";
            Regex check = new Regex(reg, RegexOptions.IgnoreCase);
            Match lCheck = check.Match(str);

            return !lCheck.Success;
        }
        #endregion

        #region 转换小数为百分数格式(四舍五入)
        ///<summary>
        /// 转换小数为百分数格式(四舍五入)
        ///</summary>
        ///<param name="f">要转换的单精度数</param>
        ///<param name="iLen">保留的小数位数</param>
        ///<returns>百分数字符串</returns>
        public static string ToPercent(float f, int iLen)
        {
            iLen = Math.Abs(iLen);
            return f.ToString(String.Format("f{0}", iLen.ToString())) + @"%";
        }
        /// <summary>
        /// 获取两个整数iMin在iMax占的百分比,可以指定精度,默认保留两位小数
        /// </summary>
        /// <param name="iMin">最小的数</param>
        /// <param name="iMax">最大的数</param>
        /// <param name="format">格式字符串,可以为空或null,保留两位小数</param>
        /// <returns>百分比字符串(类似:23%)</returns>
        public static string GetPecent(int iMin, int iMax, string format)
        {
            if (0 == iMin || 0 == iMax) return "";
            if (String.IsNullOrEmpty(format)) format = "#0.#0";

            return ((double) iMin/(double) iMax).ToString(format) + "%";
        }
        /// <summary>
        /// 获取两个整数iMin在iMax占的百分比,默认保留两位小数
        /// </summary>
        /// <param name="iMin">最小的数</param>
        /// <param name="iMax">最大的数</param>
        /// <returns>百分比字符串(类似:23%)</returns>
        public static string GetPecent(int iMin, int iMax)
        {
            return GetPecent(iMin, iMax);
        }
        #endregion

        #region "判断指定的int变量值是否在指定的范围内,不在返回默认值 public static int IsRange(int i, int iMin, int iMax, int iDefault)"
        /// <summary>
        /// 判断int变量值是否在指定的范围内,不在返回默认值
        /// </summary>
        /// <param name="i">要判断的变量</param>
        /// <param name="iMin">最小值</param>
        /// <param name="iMax">最大值</param>
        /// <param name="iDefault">默认值</param>
        /// <returns>在范围内返回原值,反之返回默认值</returns>
        public static int IsRange(int i, int iMin, int iMax, int iDefault)
        {
            return (i >= iMin && i <= iMax) ? i : iDefault;
        }

        /// <summary>
        /// 判断int变量值是否在指定的范围内,在返回true,反之,返回false
        /// </summary>
        /// <param name="i">要判断的变量</param>
        /// <param name="iMin">最小值</param>
        /// <param name="iMax">最大值</param>
        /// <returns>在范围内返回true,反之返回false</returns>
        public static bool IsRange(int i, int iMin, int iMax)
        {
            return i == IsRange(i, iMin, iMax, Int32.MinValue);
        }

        /// <summary>
        /// 判断字符串的真实长度(一个汉字算两个字符)是否在指定的范围(包含两个临界值)内.
        /// </summary>
        /// <param name="str">要判断的字符串</param>
        /// <param name="iMin">字符真实长度最小值</param>
        /// <param name="iMax">字符串真实长度最大值</param>
        /// <returns>在,返回true,反之,返回false</returns>
        public static bool IsRange(string str, int iMin, int iMax)
        {
            return IsRange(GetRealLength(str), iMin, iMax);
        }
        #endregion

        #region "获取指定的IP地址(先获取CDN的IP地址,获取不到,就获取UserHostAddress)"
        ///<summary>
        /// 获取指定的IP地址(先获取CDN的IP地址,获取不到,就获取UserHostAddress)
        ///</summary>
        ///<returns></returns>
        public static string GetIP()
        {
            string srcIp = HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
            if (srcIp == null)
            {
                srcIp = HttpContext.Current.Request.UserHostAddress;
            }
            return srcIp;
        }
        #endregion

        #region "将object转换成string对象,对象的各个属性以字符串"@_@"分隔"
        ///<summary>
        /// 将object转换成string对象,对象的各个属性以字符串"@_@"分隔
        ///</summary>
        ///<returns>转换后的字符串</returns>
        public static string ConvertObjectToString(object obj)
        {
            if (obj != null)
            {
                //获取当前对象类型内所有的公开属性
                PropertyInfo[] piSrcPropertyInfo =
                    obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

                StringBuilder result = new StringBuilder("");
                //string strReturn = string.Empty;

                //获得当前属性
                foreach (PropertyInfo piTemp in piSrcPropertyInfo)
                {
                    //获取当前属性的类型
                    Type tTemp = piTemp.PropertyType;

                    //判断当前属性类型是否为系统类型，如为系统类型则为System起始，否则为用户自定义class
                    if (tTemp.ToString().IndexOf("System.String") == 0)
                    {
                        //如果是系统类型，则直接以该类型建立表的列
                        if (0 == result.Length)
                        {
                            result.Append(String.Format("{0},{1}", piTemp.Name, piTemp.GetValue(obj, null)));
                        }
                        else
                        {
                            result.AppendFormat("@_@{0},{1}", piTemp.Name, piTemp.GetValue(obj, null));
                        }
                    }
                    else if (tTemp.ToString().IndexOf("System.DateTime") == 0)
                    {
                        //如果是系统类型，则直接以该类型建立表的列

                        if (0 == result.Length)
                        {
                            result.AppendFormat("{0},{1}", piTemp.Name, ((DateTime)piTemp.GetValue(obj, null)).ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                        else
                        {
                            result.AppendFormat("@_@{0},{1}", piTemp.Name, ((DateTime)piTemp.GetValue(obj, null)).ToString("yyyy-MM-dd HH:mm:ss"));
                            //strReturn += SystemConstant.PARSE_STRING + piTemp.Name + "," +
                            //((DateTime)piTemp.GetValue(obj, null)).ToString(SystemConstant.cs_TIME_TYPE);
                        }
                    }
                    else
                    {
                        if (0 == result.Length)
                        {
                            result.AppendFormat("{0},{1}", piTemp.Name, piTemp.GetValue(obj, null));
                        }
                        else
                        {
                            result.AppendFormat("@_@{0},{1}", piTemp.Name, piTemp.GetValue(obj, null));
                        }

                        //if (strReturn == string.Empty)
                        //{
                        //    strReturn = piTemp.Name + "," + piTemp.GetValue(obj, null);
                        //}
                        //else
                        //{
                        //    strReturn += SystemConstant.PARSE_STRING + piTemp.Name + "," +
                        //                 piTemp.GetValue(obj, null);
                        //}
                    }
                }
                return result.ToString();
            }
            return "";
        }
        #endregion

        #region "将object转换成string对象 public static void ConvertStringToObject(string key, ref object targetObj)"
        /// <summary>
        /// 将object转换成string对象
        /// </summary>
        /// <param name="key">需要转换得object对象</param>
        /// <param name="targetObj">IList中实际所包含得对象类型</param>
        /// <returns>DataSet类型对象</returns>
        public static void ConvertStringToObject(string key, ref object targetObj)
        {
            try
            {
                if (!string.IsNullOrEmpty(key))
                {
                    string[] arrKey = key.Split(new[] { "@_@" }, StringSplitOptions.None);
                    Hashtable ht = new Hashtable();

                    for (int i = 0; i < arrKey.Length; i++)
                    {
                        string[] arrParse = arrKey[i].Split(',');
                        ht.Add(arrParse[0], arrParse[1]);
                    }

                    //获取当前对象类型内所有的公开属性
                    PropertyInfo[] piSrcPropertyInfo =
                        targetObj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

                    string strReturn = string.Empty;
                    //获得当前属性
                    foreach (PropertyInfo piTemp in piSrcPropertyInfo)
                    {
                        //获取当前属性的类型
                        Type tTemp = piTemp.PropertyType;
                        string strValue = ht[piTemp.Name].ToString();

                        //判断当前属性类型是否为系统类型，如为系统类型则为System起始，否则为用户自定义class
                        if (tTemp.ToString().IndexOf("System.DateTime") == 0)
                        {
                            //如果是日期类型
                            piTemp.SetValue(targetObj, DateTime.Parse(strValue), null);
                        }
                        else if (tTemp.ToString().IndexOf("System.Int64") == 0)
                        {
                            //如果是int类型
                            piTemp.SetValue(targetObj, Int64.Parse(strValue), null);
                        }
                        else if (tTemp.ToString().IndexOf("System.Int") == 0)
                        {
                            //如果是int类型
                            piTemp.SetValue(targetObj, int.Parse(strValue), null);
                        }
                        else if (tTemp.ToString().IndexOf("System.Single") == 0)
                        {
                            //如果是float类型
                            piTemp.SetValue(targetObj, float.Parse(strValue), null);
                        }
                        else if (tTemp.ToString().IndexOf("System.Decimal") == 0)
                        {
                            //如果是Decimal类型
                            piTemp.SetValue(targetObj, Decimal.Parse(strValue), null);
                        }
                        else
                        {
                            //如果是string类型
                            piTemp.SetValue(targetObj, strValue, null);
                        }
                    }
                }
            }
            catch
            {
            }
        }
        #endregion

        #region "获取当天在本周内的天数 public static int GetDayOfWeek()"
        ///<summary>
        /// 获取当天在本周内的天数
        ///</summary>
        ///<returns>周一为第一天</returns>
        public static int GetDayOfWeek()
        {
            int iResult = 0;
            switch (DateTime.Now.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    iResult = 1;
                    break;
                case DayOfWeek.Tuesday:
                    iResult = 2;
                    break;
                case DayOfWeek.Wednesday:
                    iResult = 3;
                    break;
                case DayOfWeek.Thursday:
                    iResult = 4;
                    break;
                case DayOfWeek.Friday:
                    iResult = 5;
                    break;
                case DayOfWeek.Saturday:
                    iResult = 6;
                    break;
                case DayOfWeek.Sunday:
                    iResult = 7;
                    break;
                default:
                    break;
            }
            return iResult;
        }
        #endregion

        #region "获取当天距周末还有几天,周一为每周第一天  public static int DiffDayOfWeek()"
        /// <summary>
        /// 获取当天距周末还有几天,周一为每周第一天
        /// </summary>
        /// <returns></returns>
        public static int DiffDayOfWeek()
        {
            return 7 - GetDayOfWeek();
        }
        #endregion

        #region "生成web.config文件里machineKey配置字节里validationKey和decryptionKey"
        ///<summary>
        /// 生成web.config文件里machineKey配置字节里validationKey和decryptionKey
        /// 附参考的matchineKey配置： 
        //<?xml version="1.0"?> 
        //<configuration> 
        //  <system.web> 
        //    <machineKey validationKey="3FF1E929BC0534950B0920A7B59FA698BD02DFE8" decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A77" decryption="3DES" validation="SHA1"/> 
        //  </system.web> 
        //</configuration>
        ///</summary>
        ///<returns>validationKey和decryptionKey字符串数组</returns>
        public static string[] GetMachineKey()
        {
            string[] result = new string[2];
            result[0] = CreateKey(20);  //验证码key
            result[1] = CreateKey(24); //解密key
            return result;
        }

        internal static string CreateKey(int len)
        {
            byte[] bytes = new byte[len];
            new RNGCryptoServiceProvider().GetBytes(bytes);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < bytes.Length; i++)
            {
                sb.Append(string.Format("{0:X2}", bytes[i]));
            }
            return sb.ToString();
        }
        #endregion

        #region "获取数据库数据字典SQL语句(适用于Sql Server2005) public string GetCurrentTableSql(string tableName)"
        ///<summary>
        /// 获取数据库数据字典SQL语句(适用于Sql Server2005)
        ///</summary>
        ///<returns>SQL语句</returns>
        public static string GetDictionary()
        {
            StringBuilder sql = new StringBuilder("");
            sql.Append(@"SELECT (case when a.colorder=1 then d.name else '' end)表名,a.colorder 序号,a.name 列名,(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,");
            sql.Append(@"(case when (SELECT count(*) FROM sysobjects WHERE (name in ");
            sql.Append(@"(SELECT name FROM sysindexes WHERE (id = a.id) AND (indid in ");
            sql.Append(@"(SELECT indid FROM sysindexkeys WHERE (id = a.id) AND (colid in (SELECT colid ");
            sql.Append(@"FROM syscolumns WHERE (id = a.id) AND (name = a.name))))))) AND ");
            sql.Append(@"(xtype = 'PK'))>0 then '√' else '' end) 主键, ");
            sql.Append(@"b.name 类型, a.length 字节数, COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度, ");
            sql.Append(@"isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数, ");
            sql.Append(@"(case when a.isnullable=1 then '√'else '' end) 允许空, ");
            sql.Append(@"isnull(e.text,'') 默认值, isnull(g.[value],'') AS 描述 ");
            sql.Append(@"FROM  syscolumns  a left join systypes b on  a.xtype=b.xusertype ");
            sql.Append(@"inner join sysobjects d on a.id=d.id  and  d.xtype='U' and  d.name<>'dtproperties' ");
            sql.Append(@"left join syscomments e on a.cdefault=e.id left join sys.extended_properties g ");
            sql.Append(@"on a.id=g.major_id AND a.colid = g.major_id ");
            sql.Append(@"order by a.id,a.colorder ");
            return sql.ToString();
        }
        /// <summary>
        /// 获取指定表结构SQL语句 
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <returns>Sql语句</returns>
        public static string GetCurrentTableSql(string tableName)
        {
            StringBuilder result = new StringBuilder("");
            result.Append("SELECT 表名 = case when a.colorder=1 then d.name else '' end,");
            result.Append("表说明 = case when a.colorder = 1 then isnull(f.value,'') else '' end,");
            result.Append("字段序号=a.colorder, 字段名=a.name, 标识=case   when   COLUMNPROPERTY(   a.id,a.name,'IsIdentity')=1   then   '√'else   ''   end, ");
            result.Append("主键=case   when   exists(SELECT   1   FROM   sysobjects   where   xtype='PK'   and   name   in   ( ");
            result.Append("SELECT   name   FROM   sysindexes   WHERE   indid   in( ");
            result.Append("SELECT   indid   FROM   sysindexkeys   WHERE   id   =   a.id   AND   colid=a.colid ");
            result.Append(")))   then   '√'   else   ''   end, 类型=b.name,长度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),占用字节数=a.length, ");
            result.Append("小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0), ");
            result.Append("允许空=case   when   a.isnullable=1   then   '√'else   ''   end, ");
            result.Append("默认值=isnull(e.text,''), ");
            result.Append("字段说明=isnull(g.[value],'') FROM   syscolumns   a left   join   systypes   b   on   a.xtype=b.xusertype ");
            result.Append(" inner   join   sysobjects   d   on   a.id=d.id     and   d.xtype='U'   and     d.name<>'dtproperties' ");
            result.Append("left   join   syscomments   e   on   a.cdefault=e.id ");
            result.Append("left   join   sys.extended_properties g   on   a.id=g.major_id   and   a.colid=g.minor_id ");
            result.Append("left   join   sys.extended_properties f   on   d.id=f.major_id   and   f.minor_id   =0 ");
            result.AppendFormat("where   d.name='{0}' ", tableName);         //如果只查询指定表,加上此条件
            result.Append("order   by   a.id,a.colorder ");
            return result.ToString();
        }

        /// <summary>
        /// 获取指定数据库服务器上的所有表名
        /// </summary>
        /// <returns></returns>
        public static string GetAllTableSql()
        {
            return "select name from sysobjects where type= 'u' and name <> 'sysdiagrams'";
        }

        /// <summary>
        /// 获取数据库服务器上所有数据库名
        /// </summary>
        /// <returns></returns>
        public static string GetAllDatabase()
        {
            return "SELECT Name FROM Master..SysDatabases ORDER BY Name";
        }
        #endregion

        #region "获取MD5加密后的字符串,指定MD5加密次数(用于参数签名验证)"
        /// <summary>
        /// 获取MD5加密后的字符串,指定MD5加密次数(用于参数签名验证,最多5次)
        /// </summary>
        /// <param name="str">要加密的字符串</param>
        /// <param name="iTimes">加密次数</param>
        /// <returns>经过iTimes次加密后的密文</returns>
        public static string GetMD5(string str, int iTimes)
        {
            string result = str;
            if (0 >= iTimes || 5 < iTimes) iTimes = 1;
            for (int i = 0; i < iTimes; i++)
                result = DESncrypt.GetMD5(result);
            return result;
        }
        #endregion

        #region "取指定长度的字符串 public static string GetSubString(string src, int startIndex, int length, string tailString)"
        /// <summary>
        /// 取指定长度的字符串,真实长度.一个中文算两个字符
        /// </summary>
        /// <param name="src">要检查的字符串</param>
        /// <param name="startIndex">起始位置</param>
        /// <param name="length">指定长度</param>
        /// <param name="tailString">用于替换的字符串</param>
        /// <returns>截取后的字符串</returns>
        public static string GetSubString(string src, int startIndex, int length, string tailString)
        {
            string myResult = src;

            Byte[] bComments = Encoding.UTF8.GetBytes(src);
            foreach (char c in Encoding.UTF8.GetChars(bComments))
            {
                //当是日文或韩文时(注:中文的范围:\u4e00 - \u9fa5, 日文在\u0800 - \u4e00, 韩文为\xAC00-\xD7A3)
                if ((c > '\u0800' && c < '\u4e00') || (c > '\xAC00' && c < '\xD7A3'))
                {
                    //if (System.Text.RegularExpressions.Regex.IsMatch(src, "[\u0800-\u4e00]+") || System.Text.RegularExpressions.Regex.IsMatch(src, "[\xAC00-\xD7A3]+"))
                    //当截取的起始位置超出字段串长度时
                    if (startIndex >= src.Length)
                    {
                        return "";
                    }
                    return src.Substring(startIndex, ((length + startIndex) > src.Length) ? (src.Length - startIndex) : length);
                }
            }
            if (length >= 0)
            {
                byte[] bsSrcString = Encoding.Default.GetBytes(src);

                //当字符串长度大于起始位置
                if (bsSrcString.Length > startIndex)
                {
                    int p_EndIndex = bsSrcString.Length;

                    //当要截取的长度在字符串的有效长度范围内

                    if (bsSrcString.Length > (startIndex + length))
                    {
                        p_EndIndex = length + startIndex;
                    }
                    else
                    {
                        //当不在有效范围内时,只取到字符串的结尾

                        length = bsSrcString.Length - startIndex;
                        tailString = "";
                    }

                    int nRealLength = length;
                    int[] anResultFlag = new int[length];
                    byte[] bsResult = null;

                    int nFlag = 0;
                    for (int i = startIndex; i < p_EndIndex; i++)
                    {
                        if (bsSrcString[i] > 127)
                        {
                            nFlag++;
                            if (nFlag == 3)
                            {
                                nFlag = 1;
                            }
                        }
                        else
                        {
                            nFlag = 0;
                        }

                        anResultFlag[i] = nFlag;
                    }

                    if ((bsSrcString[p_EndIndex - 1] > 127) && (anResultFlag[length - 1] == 1))
                    {
                        nRealLength = length + 1;
                    }

                    bsResult = new byte[nRealLength];

                    Array.Copy(bsSrcString, startIndex, bsResult, 0, nRealLength);

                    myResult = Encoding.Default.GetString(bsResult);

                    myResult = myResult + tailString;
                }
            }

            return myResult;
        }
        #endregion

        ///<summary>
        /// 字符串数组转换成整型数组,不能转换的为0
        ///</summary>
        ///<param name="strs">要转换的字符串数组</param>
        ///<returns>int数组</returns>
        public static int[] ToInt(string[] strs)
        {
            return Array.ConvertAll(strs, delegate(string s) { return ToInt(s, 0); });
        }

        /// <summary>
        /// 获取HttpUtility方法编码后的字符串
        /// </summary>
        /// <param name="s">要编码的字符串</param>
        /// <param name="encode">编码格式</param>
        /// <returns>编码后的字符串或空字符串</returns>
        public static string GetUrlEncode(string s, Encoding encode)
        {
            if(String.IsNullOrEmpty(s) || encode == null) return s;
            return HttpUtility.UrlEncode(s, encode);
        }
        /// <summary>
        /// 获取HttpUtility方法解码后的字符串
        /// </summary>
        /// <param name="s">要解码的字符串</param>
        /// <param name="encode">编码格式</param>
        /// <returns>解码后的字符串或空字符串</returns>
        public static string GetUrlDecode(string s, Encoding encode)
        {
            if (String.IsNullOrEmpty(s) || encode == null) return s;
            return HttpUtility.UrlDecode(s, encode);
        }
        /// <summary>
        /// 获取HttpUtility方法UTF-8编码的字符串
        /// </summary>
        /// <param name="s">要编码的字符串</param>
        /// <returns>编码后的字符串或空字符串</returns>
        public static string GetUrlEncode(string s)
        {
            return GetUrlEncode(s, Encoding.UTF8);
        }
        /// <summary>
        /// 获取HttpUtility方法UTF-8解码后的字符串
        /// </summary>
        /// <param name="s">要解码的字符串</param>
        /// <returns>解码后的字符串或空字符串</returns>
        public static string GetUrlDecode(string s)
        {
            return GetUrlDecode(s, Encoding.UTF8);
        }

            
        

        /// <summary>
        /// 截取字符串,超过部分追加“...”
        /// </summary>
        /// <param name="obj">要截取的字符串对象</param>
        /// <param name="iMax">字符串长度</param>
        /// <returns>截取后的字符串</returns>
        public static string Left(object obj, int iMax)
        {
            if (null == obj) return "";
            return Left(obj.ToString(), iMax);
        }
        /// <summary>
        /// 获取分页时的页数
        /// </summary>
        /// <param name="pagesize">页记录数</param>
        /// <param name="rows">总记录数</param>
        /// <returns>页数</returns>
        public static int GetPageCount(int pagesize, int rows)
        {
            return (int)Math.Ceiling((double)((double)rows / (double)pagesize)); 
        }


        /// <summary>
        /// 获取字符串的真实长度,1个双字节字符串长度算2
        /// </summary>
        /// <param name="str">目标字符串</param>
        /// <returns>字符串真实长度</returns>
        public static int GetRealLength(string str)
        {
            if (String.IsNullOrEmpty(str)) return 0;
            return Encoding.Default.GetBytes(str).Length;
        }
        /// <summary>
        /// 获取字符串的真实长度,1个双字节字符串长度算2
        /// </summary>
        /// <param name="obj">目标字符串对象</param>
        /// <returns>字符串真实长度</returns>
        public static int GetRealLength(object obj)
        {
            if (null == obj) return 0;
            return GetRealLength(obj.ToString());
        }


        /// <summary>
        /// 判断字符串是否为null
        /// </summary>
        /// <param name="str">要判断的字符串</param>
        /// <returns>为null返回true,反之返回false</returns>
        public static bool IsNull(string str)
        {
            return null == str;
        }

        /// <summary>
        /// 判断变量的值是否与后边多个值中的其中一个相等,并指定是否忽略大小写
        /// </summary>
        /// <param name="str">变量名</param>
        /// <param name="isIgnoreCase">是否忽略大小写</param>
        /// <param name="values">变量的多个可能的值</param>
        /// <returns>相等,返回true,反之,返回false</returns>
        public static bool ToOnlyEquals(string str, bool isIgnoreCase, params string[] values)
        {
            if (values != null)
            {
                for (int i = 0; i < values.Length; i++)
                    if (ToCompare(str, values[i], isIgnoreCase)) return true;           
            }

            return false;
        }

        /// <summary>
        /// 判断变量的值是否与后边多个值中的其中一个相等,忽略大小写
        /// </summary>
        /// <param name="str">变量名</param>
        /// <param name="values">变量的多个可能的值</param>
        /// <returns>相等,返回true,反之,返回false</returns>
        public static bool ToOnlyEquals(string str, params string[] values)
        {
            return ToOnlyEquals(str, true, values);
        }

        /// <summary>
        /// 判断字符串变量的值是否不在后边的值列表当中(变量值与其中的任意一个都不相等),并指定是否忽略大小写
        /// </summary>
        /// <param name="str">变量名</param>
        /// <param name="isIgnoreCase">是否忽略大小写</param>
        /// <param name="values">变量的可能的值</param>
        /// <returns>任意一个不相等,返回true,反之,返回false</returns>
        public static bool ToEveryNotEquals(string str, bool isIgnoreCase, params string[] values)
        {
            for (int i = 0; i < values.Length; i++)
                if (ToCompare(str, values[i], isIgnoreCase)) return false;
            return true;
        }

        /// <summary>
        /// 判断字符串变量的值是否不在后边的值列表当中(变量值与其中的任意一个都不相等),忽略大小写
        /// </summary>
        /// <param name="str">变量名</param>
        /// <param name="values">变量的可能的值</param>
        /// <returns>任意一个不相等,返回true,反之,返回false</returns>
        public static bool ToEveryNotEquals(string str, params string[] values)
        {
            return ToEveryNotEquals(str, true, values);
        }

        ///<summary>
        /// 生成日期格式类似2009/08/25这样个美国格式(保存图片路径时会用到)
        ///</summary>
        ///<param name="dateTime">要转换成字符串的时间对象</param>
        ///<returns>转换成2009/08/25的格式</returns>
        public static string ToEnglishFormat(DateTime dateTime)
        {
            return ToEnglishFormat(dateTime, "yyyy/MM/dd");
        }

        /// <summary>
        /// 生成日期格式类似2009/08/25这样个美国格式(保存图片路径时会用到)
        /// </summary>
        /// <param name="dateTime">要转换成字符串的时间对象</param>
        /// <param name="sformat">要转成的美国时间格式</param>
        /// <returns>转换后的时间格式字符串(类似:2009/08/25)</returns>
        public static string ToEnglishFormat(DateTime dateTime, string sformat)
        {
            if (String.IsNullOrEmpty(sformat)) return "";
            return dateTime.ToString(sformat, new CultureInfo("en-US"));
        }

        /// <summary>
        /// 生成日期格式类似2009/08/25这样个美国格式(保存图片路径时会用到)
        /// </summary>
        /// <param name="obj">要转换的对象</param>
        /// <param name="sFormat">美国时间格式</param>
        /// <returns>转换后的时间格式字符串(类似:2009/08/25)</returns>
        public static string ToEnglishFormat(object obj, string sFormat)
        {
            if (null == obj) return "";
            return ToEnglishFormat(ToDateTime(obj), sFormat);
        }

        /// <summary>
        /// 转换日期对象为字符串类型(格式为:yyyy-MM-dd HH:mm:ss)
        /// </summary>
        /// <param name="obj">日期对象</param>
        /// <returns>格式化后的字符串</returns>
        public static string ToDateString(object obj)
        {
            if (null == obj) return "";
            return ToDateString(ToDateTime(obj));        
        }

        /// <summary>
        /// 转换日期对象为字符串类型(格式为:yyyy-MM-dd HH:mm:ss)
        /// </summary>
        /// <param name="date">日期对象</param>
        /// <returns>格式化后的字符串</returns>
        public static string ToDateString(DateTime date)
        {
            const string format = "yyyy-MM-dd HH:mm:ss";
            return date.ToString(format);
        }

        #region "判断对象的值是否是后面值中的一个. public static bool IsOnlyEquals(object obj, params string[] paras)"
        /// <summary>
        /// 判断对象的值是否是后面值中的一个.
        /// </summary>
        /// <param name="obj">要判断的对象</param>
        /// <param name="paras">值列表</param>
        /// <returns>对象值在值列表中,返回true;反之,返回false</returns>
        public static bool IsOnlyEquals(object obj, params string[] paras)
        {
            if (null == obj) return false;
            string s = obj.ToString();
            for (int i = 0, j = paras.Length; i < j; i++)
            {
                if (0 == String.Compare(s, paras[i], true)) return true;
            }
            return false;
        }
        #endregion

        [DllImport("kernel32")]
        private static extern void GetSystemInfo(ref CpuInfo cpuInfo);
        /// <summary>
        /// 获取CPU信息
        /// </summary>
        /// <returns>CPU信息对象</returns>
        public static CpuInfo GetCpuInfo()
        {
            CpuInfo cpu = new CpuInfo();
            GetSystemInfo(ref cpu);
            return cpu;
        }



        [DllImport("kernel32")]
        private static extern void GlobalMemoryStatus(ref MemoryInfo memoryInfo);

        /// <summary>
        /// 获取系统内存信息
        /// </summary>
        /// <returns>内存信息对象</returns>
        public static MemoryInfo GetMemoryInfo()
        {
            MemoryInfo memoryInfo = new MemoryInfo();
            GlobalMemoryStatus(ref memoryInfo);
            return memoryInfo;
        }

        #region "字符串比较 public static bool ToCompare(string str1, string str2, bool isIgnoreCase)"
        /// <summary>
        /// 字符串比较,指定是否忽略大小写
        /// </summary>
        /// <param name="str1">要比较的字符串1</param>
        /// <param name="str2">要比较的字符串2</param>
        /// <param name="isIgnoreCase">是否忽略大小写</param>
        /// <returns>字符串是否相等</returns>
        public static bool ToCompare(string str1, string str2, bool isIgnoreCase)
        {
            if (!isIgnoreCase)
                return 0 == String.Compare(str1, str2, StringComparison.Ordinal);
            return 0 == String.Compare(str1, str2, StringComparison.OrdinalIgnoreCase);
        }
        /// <summary>
        /// 字符串比较,不区分大小写
        /// </summary>
        /// <param name="str1">字符串1</param>
        /// <param name="str2">字符串2</param>
        /// <returns>相等返回true,反之,返回false</returns>
        public static bool ToCompare(string str1, string str2)
        {
            return ToCompare(str1, str2, true);
        }

        ///<summary>
        /// 判断整型变量的值是否在指定的范围内(包含最小值和最大值)
        ///</summary>
        ///<param name="i">要判断的值</param>
        ///<param name="iMin">最小值</param>
        ///<param name="iMax">最大值</param>
        ///<returns>在最小值和最大值里面,返回true,反之返回false</returns>
        public static bool ToCompare(int i, int iMin, int iMax)
        {
            return i >= iMin && i <= iMax; 
        }
        
        /// <summary>
        /// 判断字符串的长度是否在指定的值范围内(包含最小值和最大值)
        /// </summary>
        /// <param name="str">要判断长度的字符串</param>
        /// <param name="iMin">最小值</param>
        /// <param name="iMax">最大值</param>
        /// <returns>在最小值和最大值里面,返回true,反之返回false</returns>
        public static bool ToCompare(string str, int iMin, int iMax)
        {
            if (String.IsNullOrEmpty(str)) return false;
            return ToCompare(str.Length, iMin, iMax);
        }
        #endregion

        #region "日期大小比较 public static DateTime Min(DateTime time1, DateTime time2)"
        ///<summary>
        /// 获取两个日期类型当中最小的一个(2009-10-30小于2009-10-31)
        ///</summary>
        ///<param name="time1">日期对象1</param>
        ///<param name="time2">日期对象2</param>
        ///<returns>最小的一个日期对象</returns>
        public static DateTime Min(DateTime time1, DateTime time2)
        {
            return DateTime.Compare(time1, time2) > 0 ? time2 : time1;
        }

        /// <summary>
        /// 获取两个日期类型当中最小的一个(2009-10-30小于2009-10-31)
        /// </summary>
        /// <param name="time1">日期对象1</param>
        /// <param name="time2">日期对象2</param>
        /// <returns>最大的一个日期对象</returns>
        public static DateTime Max(DateTime time1, DateTime time2)
        {
            return DateTime.Compare(time1, time2) > 0 ? time1 : time2;
        }
        #endregion

        #region "手动注册Ajax方法到页面 public static string RegisterAjax(Type type, string site, bool isProfessional)"
        /// <summary>
        /// 手动注册Ajax方法到页面
        /// </summary>
        /// <param name="type">要注册的ajax方法,格式: "命名空间+类名"</param>
        /// <param name="site">站点虚拟目录名</param>
        /// <param name="isProfessional">是否是AjaxPro,反之为ajax</param>
        /// <returns>注册的脚步字符串</returns>
        public static string RegisterAjax(Type type, string site, bool isProfessional)
        {
            if (String.IsNullOrEmpty(site))
            {
                site = "";
            }
            else
            {
                site = "/" + site;
            }
            string name = "";
            StringBuilder result = new StringBuilder("");

            if (type.Assembly.FullName == null) return "注册失败!";
            if (type.Assembly.FullName.StartsWith("App_Code."))
            {
                name = String.Format("{0},App_Code", type.FullName);
            }
            else
            {
                name = String.Format("{0},{1}", type.FullName,
                                     type.Assembly.FullName.Substring(0, type.Assembly.FullName.IndexOf(",")));
            }

            if (isProfessional)
            {
                result.AppendFormat("\n<script type=\"text/javascript\" src=\"{0}/ajaxPro/prototype.ashx\"></script>", site);
                result.AppendFormat("\n<script type=\"text/javascript\" src=\"{0}/ajaxPro/core.ashx\"></script>", site);
                result.AppendFormat("\n<script type=\"text/javascript\" src=\"{0}/ajaxPro/converter.ashx\"></script>", site);
                result.AppendFormat("\n<script type=\"text/javascript\" src=\"{0}/ajaxPro/{1}.ashx\"></script>", site, name);
            }
            else
            {
                result.AppendFormat("<script type=\"text/javascript\" src=\"{0}/ajax/common.ashx\"></script>", site);
                result.AppendFormat(@"<script type='text/javascript' src='{0}/ajax/{1},App_Code.bzewmpoj.ashx'></script>", site, name);

            }
            return result.ToString();
        }
        /// <summary>
        /// 手动注册Ajax方法到页面,ajax方式,非专业版
        /// </summary>
        /// <param name="type">要注册的ajax方法,格式: "命名空间+类名"</param>
        /// <param name="site">站点虚拟目录名</param>
        /// <returns>注册的脚步字符串</returns>
        public static string RegisterAjax(Type type, string site)
        {
            return RegisterAjax(type, site, false);
        }

        /// <summary>
        /// 手动注册Ajax方法到页面,ajax方式,非专业版
        /// </summary>
        /// <param name="type">要注册的ajax方法,格式: "命名空间+类名"</param>
        /// <returns>注册的脚步字符串</returns>
        public static string RegisterAjax(Type type)
        {
            return RegisterAjax(type, "", false);
        }
        #endregion
    

    }
}